﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wsitech.Model;
using Wsitech.Utility;
using Wsitech.BLL;

public partial class Backend_Admin_Role : BackendPageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindRole();
        }
    }

    protected void bindRole()
    {
        repMain.DataSource = AdminRoleBLL.Instance.GetList();
        repMain.DataBind();
    }

    protected void repMain_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        LinkButton lbtnEnable = (LinkButton)e.Item.FindControl("lbtnEnable");
        LinkButton lbtnDisable = (LinkButton)e.Item.FindControl("lbtnDisable");

        //显示和隐藏启用与禁用按钮
        AdminRole role = e.Item.DataItem as AdminRole;
        if (role != null)
        {
            if (role.State == (int)UtilityEnum.State.Enable)
            {
                lbtnEnable.Visible = false;
            }
            if (role.State == (int)UtilityEnum.State.Disable)
            {
                lbtnDisable.Visible = false;
            }
        }
    }
    protected void repMain_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string rid = e.CommandArgument.ToString();
        switch (e.CommandName)
        {
            case "Enable":
                AdminRoleBLL.Instance.ChangeState(rid, UtilityEnum.State.Enable);
                break;
            case "Disable":
                AdminRoleBLL.Instance.ChangeState(rid, UtilityEnum.State.Disable);
                break;
            default:
                break;
        }
        Response.Redirect(Request.Url.ToString());
    }
}